//Functions for create the dealer hand and determine who wins the game

void dealer_hand()
{
	card_number_dealer=0;
	total_dealer=0;
	for (i=0;i<11;i++)
		{
		card_display[i]='y';
		}
	card_display[0]='D';
		while ((total_dealer<17)&&(card_number_dealer<5))  //  "Soft 17" condition loop.
	{
			card_number_dealer=new_card(card_number_dealer);		
			//cardTaken=getCardV(card);
			total_dealer=calculate_total_player();
			screen();		
	}
		WAIT_SEC(1)
		do            // Continue ?
		{
		notA=~ORDEN;
		if ((notA & 0b10000000)||(notA & 0b00100000))
			{
			ins=1;
			}
		}
	while(ins==0);
	ins=0;

}

void result() //say who wins
{
	CLEAR_LCD
	LCD_XY(3,1)
	LCD_TEXT("P:    D:")
	LCD_XY(6,1)
	LCD_NUMBER(total_player)
	LCD_XY(12,1)
	LCD_NUMBER(total_dealer)
	LCD_XY(3,2)
	if(total_player<22)
		{
		if ((total_player>total_dealer)||(total_dealer>21))
			{
			LCD_TEXT("You Won")
			score_player++;
			}
		else
			{
			if((total_player==21)&&(total_dealer==21)&&(card_number_player==2)&&(card_number_dealer==2))
				LCD_TEXT("Tie")
			else
				{
				if((total_player==21)&&(card_number_player==2))
					{
					LCD_TEXT("You Won")
					score_player++;
					}
				else
					{
					LCD_TEXT("You Lost")
					score_dealer++;
					}
				}
			}
		}
	else // You lose because your hand is over 21
		{
		LCD_TEXT("You Lost")
		score_dealer++;
		}
		WAIT_SEC(1)
	do            // Continue ?
		{
		notA=~ORDEN;
		if ((notA & 0b10000000)||(notA & 0b00100000))
			{
			ins=1;
			}
		}
	while(ins==0);
	total_dealer=0;
	ins=0;
}
